package com.zs.games.utils;

import java.util.Properties;

import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSenderImpl;

public class MailUtils {
	
	private static String smtpHost = "smtp.feishu.cn";
	
	private static String username="gg@lingzifu.com";
	
	private static String password = "MsiY5LwiXjb9djHj";
	
	private static int port = 587;
	
	private static String sendUser = "gg@lingzifu.com";
	
	
	/**
	 * 发送邮件
	 * **/
	public static boolean sendMail(String toMail,String mailTitle,String mailContent) {
		JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
		Properties props = mailSender.getJavaMailProperties();
		props.put("mail.transport.protocol", "smtp");
		props.put("mail.smtp.auth", "true");
		props.put("mail.smtp.starttls.enable", "true");
		props.put("mail.debug", "true");
		mailSender.setHost(smtpHost);
		mailSender.setUsername(username);
		mailSender.setPassword(password);
		if (port != 80) {
			mailSender.setPort(port);
		}
		SimpleMailMessage message = new SimpleMailMessage();
		message.setFrom(sendUser); // 邮件发送者
		message.setTo(toMail); // 邮件接受者
		message.setSubject(mailTitle); // 主题
		message.setText(mailContent); // 内容
		
		try {
			mailSender.send(message);
			return true;
		}catch(Exception e) {
			e.printStackTrace();
			return false;
		}
	}
}
